/*
Copyright 2010 Christian Dadswell
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package subscriber.chrisdadswell.co.uk;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class Activity_Dashboard extends ListActivity { 
	
    public static final String _APP_TAG = "Activity_Dashboard"; 
	static Context context;
	SharedPreferences _PREFS;
    
     // ONCREATE
     @Override 
     public void onCreate(Bundle icicle) { 
    	super.onCreate(icicle); 
		setContentView(R.layout.dashboard);
		context = this;
		// INITIALIZE PREFERENCES
		_PREFS = PreferenceManager.getDefaultSharedPreferences(this);
  
  /*SET FOOTER URL
  String blogUrl = ("<a href='http://www.chrisdadswell.co.uk/?page_id=139'" + "style='color: #ffffff'>Copyright Christian Dadswell 2010</a>");
  TextView wBlogUrl = (TextView) findViewById(R.id.txt_footer);
  wBlogUrl.setText(Html.fromHtml(blogUrl));
  wBlogUrl.setMovementMethod(LinkMovementMethod.getInstance());
  */
  String[] start_options = { "Getting Started","Mobile Google Reader","Subscription Management","Tag Management","","Follow Subscriber"};
  setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, start_options));
  getListView().setTextFilterEnabled(true);
  getListView().setSmoothScrollbarEnabled(true);
  getListView().setFadingEdgeLength(60);
     }
	 
	@Override
	protected void onListItemClick(ListView listView, View view, int position, long id) {
		    super.onListItemClick(listView, view, position, id);

		    // Get the item that was clicked 
		    Object pos = this.getListAdapter().getItem(position); 
		    String selected = pos.toString();
		    
		    if(selected == "Getting Started"){
				Intent intent = new Intent(Intent.ACTION_VIEW); 
				intent.setData(Uri.parse("http://www.chrisdadswell.co.uk/subscriber/gettingstarted"));
				startActivity(intent);
		    }else if(selected == "Mobile Google Reader") {
				Intent intent = new Intent(Intent.ACTION_VIEW); 
				intent.setData(Uri.parse("http://www.google.com/reader/i"));
				startActivity(intent);
		    }else if(selected == "Subscription Management") {
		    	Toast.makeText(Activity_Dashboard.this, "\nComing soon ...\n", Toast.LENGTH_SHORT).show();
		    	//Intent intentSubs = new Intent(Activity_Dashboard.this, Activity_Subs.class);
		    	//Activity_Dashboard.this.startActivity(intentSubs);
		    }else if(selected == "Tag Management") {
		    	Toast.makeText(Activity_Dashboard.this, "\nComing soon ...\n", Toast.LENGTH_SHORT).show();
		    	//Intent intentTags = new Intent(Activity_Dashboard.this, Activity_Tags.class);
		    	//Activity_Dashboard.this.startActivity(intentTags);
		    }else if(selected == "Follow Subscriber") {
				Intent intent = new Intent(Intent.ACTION_VIEW); 
				intent.setData(Uri.parse("http://www.twitter.com/SubscriberApp"));
				startActivity(intent);
		    }
	}
		    
	// PREPARE OPTIONS MENU
	public boolean onPrepareOptionsMenu(Menu menu) {
		menu.clear();
		menu.add(0,Constants.MENU_PREFERENCES,0,"Subscriber Preferences").setIcon(R.drawable.preferences);
		return super.onPrepareOptionsMenu(menu);
		//return true;
	}// END OF OPTIONS MENU
		
	@Override
	public boolean onOptionsItemSelected (MenuItem item){
		switch (item.getItemId()){
		case Constants.MENU_PREFERENCES:
			Intent prefsActivity = new Intent(Activity_Dashboard.this, Activity_Preferences.class);
			startActivity(prefsActivity);
			break;
		}
		return false;
		
	
	}// END OF OPTIONS SELECTED
     
// LIFECYCLES
	
     public void onStart() {
    	 super.onStart();
    	 Log.d(_APP_TAG, "---------- onStart");
     } 
     
     public void onRestart() {
    	 super.onRestart();
    	 Log.d(_APP_TAG, "---------- onReStart");
    	 }
     public void onResume() {
    	 super.onResume();
    	 Log.d(_APP_TAG, "---------- onResume");
    	 }
     public void onPause() {
    	 super.onPause();
    	 Log.d(_APP_TAG, "---------- onPause");
    	 }
     public void onStop() {
    	 super.onStop();
    	 Log.d(_APP_TAG, "---------- onStop");
    	 }
     
     public void onDestroy() {
    	 super.onDestroy();
    	 Log.d(_APP_TAG, "---------- onDestroy");
    	 }
}
